<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<%@ include file="/dwz/dwz_inc.jsp" %>
<base href="<%=basePath %>"/>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script type="text/javascript" src="ckeditor/ckeditor.js"></script>
<script type="text/javascript">
$(function(){
	DWZ.init("dwz/dwz.frag.xml", {
		loginUrl:"login.html", loginTitle:"登录",	// 弹出登录对话框
//		loginUrl:"login.html",	// 跳到登录页面
		statusCode:{ok:200, error:300, timeout:301}, //【可选】
		pageInfo:{pageNum:"pageNum", numPerPage:"numPerPage", orderField:"orderField", orderDirection:"orderDirection"}, //【可选】
		debug:false,	// 调试模式 【true|false】
		callback:function(){
			initEnv();
			$("#themeList").theme({themeBase:"dwz/themes"}); // themeBase 相对于index页面的主题base路径
		}
	});
});

</script>
</head>
<body>


					
 <form action="admin/file!rename" onsubmit="validateCallback(this, navTabAjaxDone,'确定要重命名?')" method="post">
						<input type="hidden" name="folder" value="${folder }"/>
						<input type="hidden" name="name" value="${name[0] }"/>
						<input id="name"  type="text" value="${name[0] }"
							size="30" name="name" class="required textInput">
						<intput  type="submit" value="重命名" />						
					</form>
			<div style="width:98%;height:98%" class="panel">
				<h1>fg</h1>
				<div >
				<div id="txt" style="display:none;width:98%;height:95%;">
					<div id="editor" >loading...</div>
					
				</div>
								
				<img id="img" style="display:none" alt="${name }" />
				</div>
			</div>

<script type="text/javascript">
	CKEDITOR.replace('editor');
	var editor = CKEDITOR.instances.editor;
 
	var imgFile = "*.jpg;*.jpeg;*.gif;*.png;";
	var txtFile = "*.txt;*.ini;*.conf;*.config;"+
					"*.java;*.js;*.xml";
	var webFile = "*.jsp;*.asp;*.html;*.htm;*.php;";
	var zipFile = "*.zip;*.war;*.jar;";
	
	var file={
			name:'${name[0]}',
			folder:'${folder}',
			_path:null,
			getPath:function(){
				if(this._path==null){
					this._path=escape( '${folder}/${name[0]}');
				}
				return this._path;			
			},
			getExName:function(){
				if(this._exName) return this._exName;
				if(!this.name)return "";
				var s = this.name.lastIndexOf("\.");
				if(s<0)return "";
				this._exName = "*."+this.name.substr(s+1)+";";
				return this._exName;
			}
		};
		var txt = {
				name:'文本文件',
				ex:txtFile + webFile,
				el:$("#txt"),
				proc:function(){
					this.el.css("display","block");					
					readTxt(function(txt){
						editor.setData(txt);
					});
				}	
			};
	
		var fileProc = {
		file:file,
		run:function(file){
			if(file)
				this.file = file;
			for(var i=0;i<this.procList.length;i++ ){
				var fp= this.procList[i]; 
				if(fp.ex.indexOf(this.file.getExName())>=0) {
					fp.proc();
				}
			}
		}, 
		
		
		procList:[
			 {
			name:"图片文件",
			ex:imgFile,
			el:$("#img"),
			proc:function(){				
				var p = this.el;
				p.css("display","block");
				var img = $("img",p);
				img.attr('src',this.file.getPath());
				}
			},
			txt
		]
	} ;
	
	function readTxt(cb) {
			$.ajax({
					type:'POST',
					url:"admin/file!read",
					data:{name:file.name,folder:file.folder},
					dataType:"text",
					cache: false,
					success:function(data){
			                    cb(data);
			                },
						error: function(xmlReq){							
							 cb(data);
							 if(alertMsg){
							 	alertMsg.info("load file content field");
							 }
						}
					});
	}
	fileProc.run(file);
	
</script>
</body>
</html>